package com.jpx.jxcupms.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.jpx.jxc.common.vo.ResultEntity;
import com.jpx.jxcupms.entity.TRoleMenu;
import com.jpx.jxcupms.service.ITRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Mht
 * @since 2020-02-22
 */
@RestController
@RequestMapping("/upms/tRoleMenu")
public class TRoleMenuController {
    @Autowired
    ITRoleMenuService itRoleMenuService;

    @RequestMapping("shouquan")
    @Transactional
    public ResultEntity shouquan(Integer roleid,Integer[] roleMenuList){
        Wrapper<TRoleMenu> wrapper = new EntityWrapper<TRoleMenu>();
        wrapper.eq("role_id",roleid);
        itRoleMenuService.delete(wrapper);
        List<TRoleMenu> list = new ArrayList<TRoleMenu>();
        for (Integer menuId:roleMenuList) {
            TRoleMenu tRoleMenu = new TRoleMenu();
            tRoleMenu.setMenuId(menuId);
            tRoleMenu.setRoleId(roleid);
            list.add(tRoleMenu);
        }
        itRoleMenuService.insertBatch(list);
        return ResultEntity.ok();
    }
}
